package com.yidu.BusinessParameters.controller;

import com.yidu.BusinessParameters.entity.CashAccruedEntity;
import com.yidu.BusinessParameters.entity.SecurityAccruedEntity;
import com.yidu.BusinessParameters.service.SecurityAccruedService;
import com.yidu.Util.util.Dbutil;
import com.yidu.Util.util.TableIdUtil;
import com.yidu.Util.util.TableNameUtil;
import com.yidu.Util.util.TableTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class SecurityAccruedController {

    @Autowired
    private SecurityAccruedService securityAccruedService;
    @Autowired
    Dbutil dbutil;

    @RequestMapping("/securityAccruedSelect")
    public Map securityAccruedSelect(){
        System.out.println("查询");
        List<SecurityAccruedEntity> SecurityAccruedEntitylist = securityAccruedService.securityAccruedSelect();
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",securityAccruedService.two());
        map.put("data",SecurityAccruedEntitylist);
        return map;
    }

    @RequestMapping("/securityAccruedSelects")
    public Map securityAccruedSelects(int page, int limit,SecurityAccruedEntity securityAccruedEntity){
        System.out.println("查询");
        List<SecurityAccruedEntity> SecurityAccruedEntitylist = securityAccruedService.securityAccruedSelects(page, limit,securityAccruedEntity);
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",securityAccruedService.two());
        map.put("data",SecurityAccruedEntitylist);
        System.out.println(securityAccruedEntity);
        return map;
    }

    @RequestMapping("/securityAccruedinsert")
    public int securityAccruedinsert(SecurityAccruedEntity securityAccruedEntity, String cashId, HttpServletRequest request){
        String maxId = dbutil.getMaxId3(TableIdUtil.SAID, TableNameUtil.SA, TableTimeUtil.SATime,securityAccruedEntity.getSecurityDate());
        securityAccruedEntity.setSecurityAccruedId(maxId);
        securityAccruedEntity.setCashId(cashId);
        HttpSession session = request.getSession();
        String fundId = (String) session.getAttribute("fundId");
        securityAccruedEntity.setFundId(fundId);
        System.out.println(securityAccruedEntity);
        int i = securityAccruedService.securityAccruedinsert(securityAccruedEntity);
        return i;
    }

    @RequestMapping("/securityAccrueddelete")
    public int securityAccrueddelete(String securityAccruedId){
        int i = securityAccruedService.securityAccrueddelete(securityAccruedId);
        return i;
    }

    @RequestMapping("/securityAccruedupdate")
    public int securityAccruedupdate(SecurityAccruedEntity securityAccruedEntity){
        System.out.println("============================================");
        System.out.println(securityAccruedEntity);
        int i = securityAccruedService.securityAccruedupdate(securityAccruedEntity);
        return i;
    }

}
